﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Collections.Generic;
using BDS;

/// <summary>
/// Summary description for MemberBL
/// </summary>
public class MemberBL
{   
    public static DataSet ValidateUser(string username,string password)
    {
        MemberDAO mb = new MemberDAO();
        return mb.ValidateUser(username,EncodePassword(password));
    }

    public static bool ChangePassword(string username, string oldPwd, string newPwd)
    {
        MemberDAO mb = new MemberDAO();
        if (mb.ValidateUser(username, EncodePassword(oldPwd)) != null)
            return false;        
        return mb.Changepassword(username,EncodePassword(newPwd));
    }

    public static int InsertNewMember(MembersUI member)
    {
        MemberDAO mbd = new MemberDAO();
        if (mbd.CheckUser(member.UserName)==true)        
            return -1;      
        member.Password = EncodePassword(member.Password.Trim());
        return mbd.InsertNewMember(member);
    }

    public static string EncodePassword(string password)
    {
        return Utils.DC.Web.UI.Security.Encrypt(password);
    }

    public static bool CheckUniqueCode(string refCode)
    {
        MemberDAO member = new MemberDAO();
        return member.CheckUniqueCode(refCode);
    }

    public static List<MembersUI> GetMember()
    {
        MemberDAO member = new MemberDAO();
        return member.GetMember();
    }
}
